Skip to content

Enhance search functionality to return both UI resource and text content for better client awareness#1

Open
dvejsada wants to merge 1 commit intomasterfrom
feat-add-text-to-ui
Open

Enhance search functionality to return both UI resource and text content for better client awareness#1
dvejsada wants to merge 1 commit intomasterfrom
feat-add-text-to-ui

Conversation

@dvejsada
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings January 29, 2026 18:15
@dvejsada dvejsada self-assigned this Jan 29, 2026
@dvejsada dvejsada added the enhancement New feature or request label Jan 29, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the search_web_ui tool to return both UI resources for visual display and text content for better client awareness of search results. Previously, the tool only returned a UIResource for visual display, which could leave clients (especially AI assistants) unaware of the actual search results. By adding TextContent alongside the UI, clients can now process search results both visually and programmatically.

Changes:

  • Added TextContent import from mcp.types to support returning text content alongside UI resources
  • Modified search_web_ui_tool to return both UIResource and TextContent in a list
  • Removed unused create_ui_resource import that was only referenced in commented example code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +156 to +161
text_lines = [f"Search results for: {query}\n"]
for i, item in enumerate(results, 1):
title = item.get("title", "No title")
link = item.get("link", "")
snippet = item.get("snippet", "")
text_lines.append(f"{i}. {title}\n URL: {link}\n {snippet}\n")
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text formatting has redundant newlines that create excessive spacing. Each element in text_lines already contains trailing newlines (e.g., "Search results for: {query}\n" and "{i}. {title}\n URL: {link}\n {snippet}\n"), and then line 165 joins them with additional newlines using "\n".join(text_lines). This results in double-spacing between elements. Consider either removing the trailing newlines from each line or using "".join() instead of "\n".join() to avoid the redundant spacing.

Copilot uses AI. Check for mistakes.
Comment on lines +155 to +166
# Format text content for client awareness
text_lines = [f"Search results for: {query}\n"]
for i, item in enumerate(results, 1):
title = item.get("title", "No title")
link = item.get("link", "")
snippet = item.get("snippet", "")
text_lines.append(f"{i}. {title}\n URL: {link}\n {snippet}\n")

text_content = TextContent(
type="text",
text="\n".join(text_lines)
)
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When results is empty, the text content will only show "Search results for: {query}" without any indication that no results were found. The UI component handles empty results by displaying a message ("Žádné výsledky" meaning "No results" in Czech - see search/ui.py:44-56), but the text content doesn't provide equivalent feedback. Consider adding a check for empty results and providing a clear message in the text content, such as "No results found."

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants